<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            var partitionLabels = function (s) {
                let hash = {}
                //找到每个字母的最大边界
                for (let i = 0; i < s.length; i++) {
                    hash[s[i]] = i
                }
                let result = []
                let left = 0
                let right = 0
                //遍历字符串，更新最大边界
                for (let i = 0; i < s.length; i++) {
                    right = Math.max(right, hash[s[i]])
                    //如果走到了最大边界
                    if (right == i) {
                        result.push(right - left + 1)
                        left = i + 1
                    }
                }
                return result
            }
        </script>
    </body>
</html>
